/*
 * Academic License - for use in teaching, academic research, and meeting
 * course requirements at degree granting institutions only.  Not for
 * government, commercial, or other organizational use.
 *
 * rms.c
 *
 * Code generation for function 'rms'
 *
 */

/* Include files */
#include "rms.h"
#include "rt_nonfinite.h"
#include <math.h>

/* Function Definitions */
double rms(const double xIn_data[], int xIn_size)
{
  double x_data[2000];
  double bsum;
  double y;
  int firstBlockLength;
  int ib;
  int k;
  for (firstBlockLength = 0; firstBlockLength < xIn_size; firstBlockLength++) {
    bsum = xIn_data[firstBlockLength];
    x_data[firstBlockLength] = bsum * bsum;
  }
  if (xIn_size == 0) {
    y = 0.0;
  } else {
    int lastBlockLength;
    int nblocks;
    if (xIn_size <= 1024) {
      firstBlockLength = xIn_size;
      lastBlockLength = 0;
      nblocks = 1;
    } else {
      firstBlockLength = 1024;
      lastBlockLength = xIn_size - 1024;
      nblocks = 2;
    }
    y = x_data[0];
    for (k = 2; k <= firstBlockLength; k++) {
      y += x_data[k - 1];
    }
    for (ib = 2; ib <= nblocks; ib++) {
      bsum = x_data[1024];
      if (nblocks == 2) {
        firstBlockLength = lastBlockLength;
      } else {
        firstBlockLength = 1024;
      }
      for (k = 2; k <= firstBlockLength; k++) {
        bsum += x_data[k + 1023];
      }
      y += bsum;
    }
  }
  return sqrt(y / (double)xIn_size);
}

/* End of code generation (rms.c) */
